Skip to main content

右键 摄像机上下左右移动

右键 摄像机上下左右移动

        //开启上下左右移动
if (Input.GetMouseButtonDown(1))
isMove = true;
if (Input.GetMouseButtonUp(1))
isMove = false;

if (isMove)
{
Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
print(pos);

//限制超出屏幕
if (pos.x < -13)
pos.x = -13;
else if (pos.x >13)
pos.x = 13;

if (pos.y > 3)
pos.y = 3;
else if (pos.y < -3)
pos.y = -3;

transform.position = new Vector3(Mathf.Lerp(transform.position.x, pos.x, 1.5f * Time.deltaTime), Mathf.Lerp(transform.position.y, pos.y, 1.5f * Time.deltaTime), pos.z);

}